#include <bits/stdc++.h>
using namespace std;

string s;
int m;
int a;
string shu[20]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string lian[20]={"","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"};

void solve(int begin,int end)
{
	string ss=s.substr(begin,end-begin+1);
	for(int i=0;i<ss.size();i++)
	{
		int p=1;
		while(true)
		{
			if(ss[i]==ss[i+1]&&i+1<=ss.size()-1)
			{
				p++;
				i++;
			}
			else break;
		}
		if(p>=2&&p<=10)
		{
			cout << lian[p] << " ";
			cout << shu[ss[i]-'0'] << " ";
		}
		else if(p==1||p==11)
		{
			for(int j=1;j<=p;j++)
			{
				cout << shu[ss[i]-'0'] << " ";
			}
		}
	}
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		cin >> s;
		cin >> m;
		int st=0;
		for(int i=1;i<=m;i++)
		{
			cin >> a;
			solve(st,st+a-1);
			st=st+a;
		}
		cout << endl;
	}
    return 0;
}

